<template>
  <div class="adminmyfeedback">
    <div class="adminmsg">
      <h2>我的反馈</h2>
      <div class="title block">
        <span>反馈列表</span>
      </div>
      <div v-for="item in list" :key="item.id">
        <div class="info block">
          <div class="msg">
            <h3>{{ item.title }}</h3>
            <p>反馈内容：{{ item.content }}</p>
            <p>系统回复：{{ item.reply }}</p>
          </div>
          <div>
            <el-button @click="remoke(item.id)" type="text" size="small">删除反馈</el-button>
          </div>
        </div>
      </div>
      <div class="Page">
        <el-pagination @current-change="handlePage" :current-page.sync="currentPage" layout="prev, pager, next"
          :total="allList.length" :page-size="4">
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import jwt_decode from 'jwt-decode'
export default {
  name: 'AdminMyfeedback',
  created() {
    this.getmyFBList()
  },
  data() {
    return {
      //当前页
      currentPage: 1,
      //反馈列表
      allList: [],
      list: [],
    }
  },

  methods: {
    //分页
    handlePage(page) {
      const start = (page - 1) * 4
      const end = page * 4
      this.list = this.allList.slice(start, end)
    },
    //获取当前用户反馈列表
    async getmyFBList(page = 1) {
      let token = localStorage.getItem('mytoken')
      let decoded = jwt_decode(token)
      let { data: res } = await this.$axios.get(`/api/feedback//info/${this.$store.getters.getUserInfo.id}`)
      if (res.status == '200') {
        this.allList = res.data
        this.list = this.allList.slice(0, 4)
      }
      this.handlePage(page)
    },
    //删除反馈
    async remoke(id) {
      const { data: res } = await this.$axios.get(`/api/feedback/delete/${id}`)
      if (res.status == '200') {
        this.$message({
          message: '删除成功',
          type: 'success'
        })
      } else {
        this.$message({
          message: '删除失败',
          type: 'error'
        })
      }
      this.getmyFBList(this.currentPage)
    }
  }
}
</script>

<style scoped>
.adminmyfeedback {
    width: 100%;
    min-height: calc(100vh - 60px);
    background-color: #f5f7fa;
    padding: 30px;
    box-sizing: border-box;
}

.adminmsg {
    width: 100%;
    background-color: #fff;
    border-radius: 12px;
    padding: 30px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.adminmsg h2 {
    font-size: 22px;
    font-weight: 600;
    color: #303133;
    margin-bottom: 25px;
    padding-bottom: 15px;
    border-bottom: 1px solid #ebeef5;
}

.Page {
    display: flex;
    justify-content: center;
    margin-top: 40px;
    padding-top: 20px;
    border-top: 1px solid #ebeef5;
}

.block {
    display: flex;
    align-items: center;
    width: 100%;
    flex-wrap: wrap;
    gap: 20px;
}

.title {
    height: 50px;
    background-color: #4b5fff;
    color: white;
    padding: 0 20px;
    margin: 25px 0 15px;
    border-radius: 8px;
    font-weight: 500;
    display: flex;
    align-items: center;
}

.title span {
    flex: 1;
}

.info {
    padding: 25px 0;
    border-bottom: 1px solid #ebeef5;
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    transition: all 0.3s ease;
}

.info:hover {
    background-color: #fafafa;
}

.info .msg {
    color: #606266;
    line-height: 1.6;
    flex: 1;
    min-width: 250px;
}

.msg h3 {
    font-size: 18px;
    font-weight: 600;
    color: #303133;
    margin-bottom: 8px;
}

.el-button {
    transition: all 0.3s;
}

.el-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

@media (max-width: 768px) {
    .adminmyfeedback {
        padding: 15px;
    }

    .adminmsg {
        padding: 20px;
    }
}
</style>